/**
         数组对象
   var objectArray: Array = new Array(
    {"type":"pic", "num":"1" },
    {"type":"text", "num":"2" },
    {"type":"swf", "num":"3" },
    {"type":"html", "num":"4" }
   );
   var json1:String = JSON.encode(objectArray);
 */
package com._public._json{

	public final class JSON {
		public static function encode(o:Object):String {
			return new JSONEncoder(o).getString();
		}

		public static function decode(s:String, strict:Boolean = true):* {
			return new JSONDecoder(s, strict).getValue();
		}

		/**替换单引号 */
		public static function formatJSON(s:String):String {
			var str:String = s;
			var pattern:RegExp = /'/g;  //替换单引号
			str = str.replace(pattern, "\"");
			pattern = / /g; //空格		//替换空格
			str = str.replace(pattern, "");
			pattern = /\{([^"^:]*):/g; //$1分组
			str = str.replace(pattern, "{\"$1\":");
			pattern = /,([^"^:]*):/g;
			str = str.replace(pattern, ",\"$1\":");
			return str;
		}
	}
}